﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Data;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Imaging;
using System.Windows.Shapes;

namespace AssignmentsManage.Windows
{
    /// <summary>
    /// Interaction logic for SetupWindow.xaml
    /// </summary>
    public partial class SetupWindow : Window
    {
        ToolTip tipStart = new ToolTip();

        public SetupWindow()
        {
            InitializeComponent();
        }

        private void btnOK_Click(object sender, RoutedEventArgs e)
        {
            this.DialogResult = true;
            this.Close();
        }

        private void btnExisting_Click(object sender, RoutedEventArgs e)
        {
            Microsoft.Win32.OpenFileDialog ofd = new Microsoft.Win32.OpenFileDialog();
            ofd.Filter = "Assignment Manage File (*.asmng)|*.asmng";
            if (txtFilePath.Text != string.Empty) { ofd.FileName = txtFilePath.Text; }

            if (ofd.ShowDialog().Value == true)
            {
                txtFilePath.Text = ofd.FileName;
            }
        }

        private void btnCreate_Click(object sender, RoutedEventArgs e)
        {
            Microsoft.Win32.SaveFileDialog sfd = new Microsoft.Win32.SaveFileDialog();
            sfd.Filter = "Assignment Manage File (*.asmng)|*.asmng";
            sfd.FileName = "New Assginment Manage File";

            if (sfd.ShowDialog().Value == true)
            {
                txtFilePath.Text = sfd.FileName;
            }
        }

        private void txtFilePath_TextChanged(object sender, TextChangedEventArgs e)
        {
            btnOK.IsEnabled = (txtFilePath.Text != String.Empty) || ResetColumnOrderSet || ChangeTheme;
        }

        private void btnColumnReset_Click(object sender, RoutedEventArgs e)
        {
            ResetColumnOrderSet = true;
            btnOK.IsEnabled = (txtFilePath.Text != String.Empty) || ResetColumnOrderSet || ChangeTheme;
        }

        private void cboThemes_SelectionChanged(object sender, SelectionChangedEventArgs e)
        {
            ChangeTheme = true;
            btnOK.IsEnabled = (txtFilePath.Text != String.Empty) || ResetColumnOrderSet || ChangeTheme;
        }

        #region Properties

        public bool ResetColumnOrderSet
        { get; set; }

        public bool ChangeTheme
        { get; set; }

        #endregion

        private void Window_Loaded(object sender, RoutedEventArgs e)
        {
            if (AssignmentsManage.Properties.Settings.Default.filePath == null ||
                AssignmentsManage.Properties.Settings.Default.filePath == String.Empty)
            {
                tipStart.Style = (Style)this.Resources.MergedDictionaries[0]["ToolTipLeftArrowStyle"];
                tipStart.Content = "Create or select a file to begin";
                tipStart.StaysOpen = false;
                tipStart.PlacementTarget = txtFilePath;
                tipStart.Placement = System.Windows.Controls.Primitives.PlacementMode.Right;
                tipStart.PlacementRectangle = new Rect(new Point(txtFilePath.ActualWidth, -40), new Point(100, 40));
                tipStart.IsOpen = true;
            }

            ChangeTheme = false;
            ResetColumnOrderSet = false;
        }
    }
}
